package com.leo.ibatis.demo.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.leo.ibatis.demo.domain.Orders;

public class OrdersValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return Orders.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "orderid", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userid", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "orderdate", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shipaddr1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shipcity", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shipstate", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shipzip", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shipcountry", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billaddr1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billcity", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billstate", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billzip", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billcountry", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "courier", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "totalprice", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billtofirstname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billtolastname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shiptofirstname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shiptolastname", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditcard", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "exprdate", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardtype", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "locale", "required");
	}

}
